import { Button, Upload } from 'antd';
import React, { useState } from 'react';
import './App.css'
import { UploadChangeParam, UploadFile } from 'antd/es/upload';

function App() {
  const [urls, setUrls] = useState<string[]>([])
  const handleChange = (info: UploadChangeParam<UploadFile<any>>) => {
    if (info.file.response) {
      const { data, code } = info.file.response

      if (code === 200) {
        setUrls([...urls, data.url])
      }
    }
  }
  return (
    <div className="App">
      <Upload.Dragger
        className='upload'
        onChange={(info) => handleChange(info)}
        action="/api/upload"
        itemRender={() => <></>}
        multiple
      >
        <Button type="primary">上传</Button>
      </Upload.Dragger>

      {
        urls.map((v, i) => {
          return <img src={v} key={i} height={200} alt="" />
        })
      }
    </div>
  );
}

export default App;
